Skip to content

Conversation

nstrayer
Copy link
Contributor

@nstrayer nstrayer commented Oct 14, 2025

Addresses #9877, #9909, and #9849.

Summary

This is a general bug-bash pr for markdown rendering in positron notebooks. It addresses two focus-related bugs and improves markdown syntax highlighting in Positron notebooks.

  1. Double-clicking to edit markdown cells loses focus (Creating a new markdown cell does not default to edit mode #9877): When double-clicking a collapsed markdown cell to enter edit mode, focus would jump to the top of the notebook instead of entering the editor. This was caused by a race condition where the Monaco editor's model wasn't fully loaded before attempting to focus.

  2. Ellipsis button click causes focus jump (Clicking on the ellipses for a collapsed markdown cell brings you to the top of the notebook #9909): Clicking the ellipsis (more actions) button on a collapsed markdown cell would cause focus to jump to the top of the notebook. This occurred because the button's click event wasn't stopped from propagating to the cell wrapper, which triggered cell deselection logic.

  3. *Markdown syntax highlighting: Markdown code blocks in notebook cells now use VSCode's tokenization system with .mtk* classes that automatically match the current theme etc.. This avoids needing to call to an async command and speeds up rendering/ makes it more debugable.

Old

image

New look

image

Release Notes

New Features

  • N/A

Bug Fixes

  • N/A

QA Notes

@:positron-notebooks

Markdown cell focus behavior:

  • Test double-clicking and pressing Enter on collapsed markdown cells to enter edit mode
  • Verify focus stays in the editor and doesn't jump to the top of the notebook
  • Test rapid cell navigation while markdown editor is loading

Markdown cell action buttons:

  • Test clicking the ellipsis (...) button and other action buttons on collapsed markdown cells
  • Verify focus remains stable and menus appear correctly

Markdown syntax highlighting:

  • Test markdown cells with code blocks in various languages (Python, R, JavaScript, etc.)
  • Switch between different themes (Dark+, Light+, custom themes)
  • Verify syntax highlighting colors update to match the current theme
  • Compare with Monaco editor syntax highlighting to ensure colors match
  • Test that local image references in markdown cells still render correctly

Copy link

github-actions bot commented Oct 14, 2025

E2E Tests 🚀
This PR will run tests tagged with: @:critical @:positron-notebooks

readme  valid tags

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes two focus-related bugs with markdown cells in Positron notebooks: double-clicking to edit markdown cells losing focus (#9877) and ellipsis button clicks causing focus jumps (#9909). The fixes address race conditions in event propagation and editor initialization.

Key changes:

  • Enhanced the selection state machine with better focus management and race condition prevention
  • Fixed ellipsis button event propagation to prevent unwanted cell deselection
  • Improved markdown cell editor initialization to ensure proper focus timing

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/e2e/tests/notebook/notebook-focus-and-selection.test.ts Unskipped a test that was previously failing due to the focus bugs
src/vs/workbench/contrib/positronNotebook/browser/selectionMachine.ts Enhanced selection state machine with improved focus management and race condition prevention
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/actionBar/NotebookCellMoreActionsMenu.tsx Added event propagation prevention to ellipsis button click handler
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/NotebookMarkdownCell.tsx Removed double-click handler from markdown cell rendering
src/vs/workbench/contrib/positronNotebook/browser/notebookCells/CellEditorMonacoWidget.tsx Added selection state validation to prevent stale focus requests
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookInstance.ts Simplified cell creation logic to use the enhanced selection state machine
src/vs/workbench/contrib/positronNotebook/browser/PositronNotebookCells/PositronNotebookMarkdownCell.ts Enhanced editor initialization with proper async handling and text model loading
src/vs/workbench/contrib/positronNotebook/browser/IPositronNotebookInstance.ts Removed obsolete setEditingCell method from interface

@nstrayer nstrayer force-pushed the positron-nb-markdown-expand-bug branch 2 times, most recently from b6feb92 to 6445435 Compare October 15, 2025 20:48
@nstrayer nstrayer requested review from Copilot and seeM October 15, 2025 20:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.

await extensionService.whenInstalledExtensionsRegistered();

const languageId = languageService.getLanguageIdByLanguageName(lang)
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?]/, 1)[0]);
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The regular expression has an unmatched closing bracket ] without a corresponding opening bracket. This will cause a syntax error. The regex should be /\s+|:|,|(?!^)\{|\?/ (remove the ]).

Suggested change
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?]/, 1)[0]);
?? languageService.getLanguageIdByLanguageName(lang.split(/\s+|:|,|(?!^)\{|\?/, 1)[0]);

Copilot uses AI. Check for mistakes.

Comment on lines +46 to +52
* NOTE: This code is duplicated from markdownDocumentRenderer.ts (MarkedHighlight namespace)
* which itself copied it from https://github.com/markedjs/marked-highlight.
*
* We duplicate it here rather than modifying upstream code to avoid merge conflicts.
* The MarkedHighlight namespace is private in upstream, so we can't import it.
*
* If VSCode upstream exports this utility in the future, we should use that instead.
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicated code creates maintainability concerns. Consider extracting the shared functionality into a common utility module that both files can import, rather than duplicating the implementation.

Copilot uses AI. Check for mistakes.

Comment on lines +89 to +94
* In <pre> elements, whitespace must be preserved per HTML spec.
*
* This is an O(n) operation, where n is the depth of the node in the tree which
* is not super ideal and could be optimized with additional state tracking if
* needed but until we see performance issues the encapsulation provided by
* this implementation is worth it.
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The O(n) tree traversal for every text node could impact performance with deeply nested HTML structures. Consider tracking pre-element state during parsing to avoid repeated traversals.

Copilot uses AI. Check for mistakes.

@nstrayer nstrayer force-pushed the positron-nb-markdown-expand-bug branch from 6445435 to 51fc434 Compare October 16, 2025 14:52
@cindyytong
Copy link

Humble request where there are UI changes can you pls include a video for me to review. This may also help QA. My code reviews won't be great :)

Thanks

@nstrayer nstrayer force-pushed the positron-nb-markdown-expand-bug branch from 51fc434 to 6a07722 Compare October 16, 2025 16:09
@nstrayer nstrayer requested a review from Copilot October 16, 2025 16:17
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.

Copy link
Contributor

@seeM seeM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code changes look great! I remember we spoke a long time ago about focus being a real pain point across notebook UIs, so this is very important

* We duplicate it here rather than modifying upstream code to avoid merge conflicts.
* The MarkedHighlight namespace is private in upstream, so we can't import it.
*
* If VSCode upstream exports this utility in the future, we should use that instead.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't expect to change their implementation, it shouldn't cause bad conflicts to add an export to the upstream code. But if we don't really need to stay in sync with any upstream changes, copy pasting is fine too

// Watch for editor focus requests from the cell
React.useLayoutEffect(() => {
// Subscribe to focus request signal - triggers whenever requestEditorFocus() is called
const disposable = autorun(reader => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently realized that autorun also has an initial run on definition. Where we don't want that we might prefer something like runOnChange

Copy link

@cindyytong cindyytong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! ty for the screenshots

@nstrayer nstrayer merged commit 1c69861 into main Oct 20, 2025
14 checks passed
@nstrayer nstrayer deleted the positron-nb-markdown-expand-bug branch October 20, 2025 15:20
@github-actions github-actions bot locked and limited conversation to collaborators Oct 20, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants